//
//  HPHttpTool.m
//  韩鹏微博
//
//  Created by hanpeng on 15-11-23.
//  Copyright (c) 2015年 hanpeng. All rights reserved.
//

#import "HPHttpTool.h"
#import "AFNetworking.h"
@implementation HPHttpTool
+(void)POSTWithUrl:(NSString *)url param:(NSDictionary *)param
           succees:(void (^) (id json)) succees failure :(void (^) (NSError * error )) failure
{
    AFHTTPRequestOperationManager * mgr = [AFHTTPRequestOperationManager manager];
    [mgr POST:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (succees) {
        succees(responseObject);
          
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];


}

+(void)GETWithUrl:(NSString *)url param:(NSDictionary *)param
          succees:(void (^) (id json)) succees failure :(void (^) (NSError * error )) failure
{
    AFHTTPRequestOperationManager * mgr = [AFHTTPRequestOperationManager manager];
    [mgr GET:url parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (succees) {
            succees(responseObject);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];

}


+(void)POSTWithUrl:(NSString *)url param:(NSDictionary *)param constructingBodyWithBlock:(void(^)(id< AFMultipartFormData> formData))block succees:(void (^) (id json)) succees failure :(void (^) (NSError * error )) failure

{
  AFHTTPRequestOperationManager * mgr = [AFHTTPRequestOperationManager manager];
 [mgr POST:url parameters:param constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
     
     if(block)
         block(formData);

 } success:^(AFHTTPRequestOperation *operation, id responseObject) {
     if (succees) {
         succees(responseObject);
     }
 } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
     if (failure) {
         failure(error);
     }
 }];


}

@end
